import java.util.ArrayList;

public class Demo4 {
    public int kthSmallest(TreeNode root, int k) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        return func(root, k, arrayList);
    }

    public int func(TreeNode root, int k, ArrayList arrayList) {
        func(root.left, k, arrayList);
        arrayList.add(root.val);
        func(root.right,k,arrayList);
        return arrayList.get(k);
    }
}
